<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>管理员登录</title>  
    <link rel="shortcut icon" type="image/x-icon" href="${pageContext.request.contextPath }/images/icon.ico" media="screen" /> 
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    
    <!-- 弹框的相关文件 -->
	<link href="${pageContext.request.contextPath}/css/addAlertCss/main.css" rel="stylesheet" type="text/css"/>
	<script src="${pageContext.request.contextPath}/js/addAlertJs/qikoo.js"></script>

    <script type="text/javascript">
    //	检验手机号是否为11位且全为数字
    function checkEmpPhoneNum(a) {
    	
	   	if(a.length != 11 || isNaN(a)){
	   		return false;
	   	}else{
	   		return true;
	   	}
	   	
    }
   
	function mySubmit(flag){  
		    return flag;  
	}

    function toSubmit(){
        var phone = $("#phone").val();
        // 船检局版本因为单位管理员的账号不止是手机号，所以去掉该判断
        if(!checkEmpPhoneNum(phone)){
            qikoo.dialog.alert("手机号格式错误！请正确输入！");
            return mySubmit(false);

        }else if($("#psw").val()==""){
            qikoo.dialog.alert("请输入密码！");
            return mySubmit(false);
        }else{
            $.post(
                "${pageContext.request.contextPath}/user/loginGetRandom",
                {"phone":$("#phone").val(),"psw":$("#psw").val()},
                function(data){
                    if(200 == data.code){
                        //签章信息
                        var random = data.phoneLoginInfo.random;
                        var signature = "qianming";
                        $.post(
                            "${pageContext.request.contextPath}/user/signatureTrack",
                            {"personId":data.phoneLoginInfo.personId,"signature":signature,"phone":data.phoneLoginInfo.phone},
                            function(data){
                                console.log(data.personId);
                                if(200 == data.code){
                                    console.log(data);
                                    window.location.href="${pageContext.request.contextPath}/user/goToPage?personId="+data.personId+"";
                                }else{
                                    qikoo.dialog.alert(data.errorMsg);
                                }

                            },
                            "json"
                        );
                    }else{
                        qikoo.dialog.alert("获取随机数失败！");
                    }
                },
                "json"
            );
        }

    }

    // 跳转到app验证码登录的页面并生成验证码存储到数据库
    function toLoginByApp(){

        var adminPhoneNum = $.trim($("#adminPhoneNum").val());

        if(adminPhoneNum == "" || !checkEmpPhoneNum(adminPhoneNum)){
            qikoo.dialog.alert("请先输入正确格式的手机号！");
        }else{
            qikoo.dialog.alert("页面跳转后请打开app查看验证码！");
            window.location.href="${pageContext.request.contextPath}/activate_toLoginByAppPage.action?adminPhoneNum="+adminPhoneNum+"";
        }


    }

    // 跳转到盖章人登录
    function toSignerLoginPage(){

        window.location.href="${pageContext.request.contextPath}/user/toSignerLoginPage";

    }

    </script>  
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:150px;"></div>
            <div class="media media-y margin-big-bottom">           
            </div>         
            <form id="loginForm" >
            <div class="panel loginbox">
                <div class="text-center margin-big padding-big-top"><h1>ESS印章管理系统</h1></div>
<!--                 	<font align=center">北京诚利通数码技术有限公司</font> ESS电子签章管理系统-->
           		<div align="center">北京诚利通数码技术有限公司</div>
                <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                	<span style="color:red">${errorMsg}</span>
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="text" class="input input-big" name="phone" id="phone" placeholder="登录账号" data-validate="required:请填写手机号" />
                            <span class="icon icon-user margin-small"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="password" class="input input-big" name="psw" id="psw" placeholder="登录密码" data-validate="required:请填写验证码" />
                            <span class="icon icon-key margin-small"></span>
                        </div>
                    </div>
                </div>
                <div style="padding:10px;"><input type="button" class="button button-block bg-main text-big input-big" value="登录" onclick="toSubmit()"></div>
                <div style="padding:10px;"><input type="button" class="button button-block bg-main text-big input-big" value="跳转到盖章人登录" onclick="toSignerLoginPage()"></div>
            </div>
            </form>          
        </div>
    </div>
</div>

</body>
</html>